package cn.edu.scau.nursingcenter.service.impl;

import java.util.List;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.scau.nursingcenter.dao.Bed_informationRepository;
import cn.edu.scau.nursingcenter.entiry.Bed_information;
import cn.edu.scau.nursingcenter.service.Bed_informationService;

/**
 * 业务逻辑层接口实现类：Bed_informationServiceImpl
 * @author feng
 *
 */
@Service
public class Bed_informationServiceImpl implements Bed_informationService{

	@Autowired
	private Bed_informationRepository bed_informationRepository;
	
	/**
	 * 显示所有床位信息
	 * @return
	 */
	@Override
	public List<Bed_information> selectAll() {
		return bed_informationRepository.findAll();
	}
	/**
	  * 新建床位
	 * @param bed_information 床位信息对象
	 * @return
	 */
	@Override
	public Bed_information insert(Bed_information bed_information) {
		return bed_informationRepository.save(bed_information);
	}
	/**
	 * 修改床位
	 * @param bed_information床位信息对象
	 * @return
	 */
	@Override
	public Bed_information update(Bed_information bed_information) {
		return bed_informationRepository.save(bed_information);
	}
	/**
	 * 根据床位编号删除床位
	 * @param id
	 */
	@Override
	public void delete(Integer id) {
		bed_informationRepository.deleteById(id);
	}
	/**
	 * 根据客户名字查询
	 * @param name客户名字
	 * @return
	 */
	@Override
	public List<Bed_information> findByName(String name) {
		return bed_informationRepository.findByName(name);
	}
	/**
	  * 根据客户编号查询
	 * @param id 客户编号
	 * @return
	 */
	@Override
	public Bed_information findByCid(Integer id) {
		Optional<Bed_information> optional = bed_informationRepository.findByCid(id);
		return optional.isPresent()?optional.get():null;
	}

}
